/**
 * Copyright (c) 2018 开源 All rights reserved.
 * <p>
 * https://www.sxyc.io
 * <p>
 * 版权所有，侵权必究！
 */

package io.renren.controller;

import io.renren.annotation.Login;
import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.utils.Result;
import io.renren.modules.yckj.common.ThreadLocalUtil;
import io.renren.modules.yckj.dto.AssetLogDTO;
import io.renren.modules.yckj.service.AssetLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测试接口
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/yckj/asset")
@Tag(name = "资产接口")
@AllArgsConstructor
public class ApiAssetLogController {

    private final AssetLogService assetLogService;
//
//    @Login
//    @GetMapping("recharge/list")
//    @Operation(summary = "充值列表")
//    @ApiResponse(content = @Content(mediaType = "application/json",
//            schema = @Schema(implementation = AssetLogDTO.class)))
//    public Result<List<AssetLogDTO>> rechargeList() {
//        Map<String, Object> map = new HashMap<>();
//        map.put("userId", ThreadLocalUtil.getUserId());
//        map.put("type", AssetType.RECHARGE.getCode());
//        List<AssetLogDTO> list = assetLogService.list(map);
//        return new Result<List<AssetLogDTO>>().ok(list);
//    }

    @Login
    @GetMapping("list")
    @Operation(summary = "变动明细")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = AssetLogDTO.class)))
    public Result<List<AssetLogDTO>> list() {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", ThreadLocalUtil.getUserId());
        List<AssetLogDTO> list = assetLogService.list(map);
        return new Result<List<AssetLogDTO>>().ok(list);
    }

    @Login
    @GetMapping("page")
    @Operation(summary = "变动明细分页")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = AssetLogDTO.class)))
    @Parameters({
            @Parameter(name = Constant.PAGE, description = "当前页码，从1开始", required = true),
            @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
            @Parameter(name = Constant.ORDER_FIELD, description = "排序字段"),
            @Parameter(name = Constant.ORDER, description = "排序方式，可选值(asc、desc)")
    })
    public Result<PageData<AssetLogDTO>> page(@RequestParam Map<String, Object> params) {
        params.put("userId", ThreadLocalUtil.getUserId());
        PageData<AssetLogDTO> page = assetLogService.page(params);
        return new Result<PageData<AssetLogDTO>>().ok(page);
    }
}